using System.Text.RegularExpressions;

namespace Test.ConsoleProgram.Algorithm.Work
{
    [TestDescription("工作逻辑: 枚举与自定义字符串互相转化")]
    public class Test_EnumCustomizeStringConvert : AbsBaseTestItem
    {
        public enum EType
        {
            /// <summary>
            /// 无数据
            /// </summary>
            None,

            /// <summary>
            /// 用户注册增长数
            /// </summary>
            UserGrowth,
        }

        public override void OnTest()
        {
            Assert.TestExe(ToString, EType.None, "OGoals/None");
            Assert.TestExe(ToString, EType.UserGrowth, "OGoals/UserGrowth");

            Assert.TestExe(ToEType, "OGoals/None", EType.None);
            Assert.TestExe(ToEType, "OGoals/UserGrowth", EType.UserGrowth);
            Assert.TestExe(ToEType, "OGoals/DDDDDD", EType.None);
            Assert.TestExe(ToEType, "sdfsdf", EType.None);
        }

        public string ToString(EType type)
        {
            return $"OGoals/{type.ToString()}";
        }
        public EType ToEType(string eTypeString)
        {
            var key = Regex.Replace(eTypeString, @"OGoals/(\w+)", "$1");
            if (System.Enum.TryParse(key, out EType v))
            {
                return v;
            }
            return EType.None;
        }
    }
}
